<?php


namespace App\Models;


use App\Http\Constants\VerificationModeConstants;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\CoinsApplication
 *
 * @method static \Illuminate\Database\Eloquent\Builder|CoinsApplication newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|CoinsApplication newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|CoinsApplication query()
 * @mixin \Eloquent
 */
class CoinsApplication extends Model
{
    protected $table = 'life_coins_application';

    protected $appends = ['verify_type_name'];
    protected $fillable = [
        'id',
        'name',
        'description',
        'app_id',
        'status',
        'verify_type',
        'verify_url',
        'settle_rule_id',
        'is_manual',
        'is_deduct',
        'created_at',
        'updated_at',
    ];

    protected $casts = [
        'name' => 'string',
        'app_id' => 'string',
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    protected function getVerifyTypeNameAttribute($value)
    {
        $attributes = $this->attributes;
        $value = array_key_exists('verify_type', $attributes) ? $attributes['verify_type'] : null;
        if (is_null($value)) return null;
        $map = array_column(VerificationModeConstants::VERIFICATION_MODE,'label','value');
        return array_key_exists($value,$map)? $map[$value]:null;
    }
}
